<?php
namespace app\daifast\controller; 
use \think\Db;


class Group extends \think\Controller
{
    //用户组列表
    public function groupList(){
        $data = Db::table('sys_admin_group')->paginate(10);
        $listArr = $data->items();
        $pages = $data->render();
        return $this->allFetch(get_defined_vars());
    }
        
    //添加或编辑用户组
    public function groupAdd(){
        $groupId = input('groupId');
        if(input('sbt')){
            
             $leftnav = input('leftnav/a');
             $ids = implode(",", $leftnav);
             $data['roles'] = $ids;
             $data['names'] = input('groupName');
             $data['on_time'] = time();
             if($groupId){ 
                 Db('sys_admin_group')->where('id',intval($groupId))->update($data);
             }else{ 
                 Db('sys_admin_group')->insert($data);
             }
             
             $this->showMsg('操作成功', url('Group/grouplist'));
             
        }
       
        $menu = Db::table('sys_menu')->select();
        $groupId and $userGroup = Db('sys_admin_group')->where(['id'=>$groupId])->find(); 
        $idsArr = explode(",", $userGroup['roles']); 
        $menu_item = Db::table('sys_menu_item')->select(); 
        foreach ($menu_item as $k=>$v) $item_arr[$v['pid']][] = $v;
        
        
         
        return $this->allFetch(get_defined_vars());
    }
    
    
    
    
    //用户组删除
    public function delete(){
        Db::table('sys_admin_group')->where('id', input('group_id'))->delete();
        echojson("ok", 1);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
